package xj.graph2d.app.prop;

import java.awt.BorderLayout;
import java.awt.Component;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import xj.app.LookAndFeelManager;

import static xj.app.BaseApplicationFrame.getResourceString;

public class TabbedAttributePane 
  extends JTabbedPane { 

  public static final int MODEL_PANE = 0;

  public static final int VISUAL_PANE = 1;

  public TabbedAttributePane(ModelPropertiesPane prop,
			     DrawShapePropertyPane vattr) {

    panels = new JPanel[2];
    labels = new String[2];
    tabTips = new String[2];

    panels[0] = prop;
    labels[0] = getResourceString("ModelPanel.tab");
    tabTips[0] = getResourceString("ModelPanel.tip");
    panels[1] = vattr;
    labels[1] = getResourceString("VisualPanel.tab");
    tabTips[1] = getResourceString("VisualPanel.tip");

    int n = 2;
    for (int i = 0; i < n; i++) {
      String tip = tabTips[i];
      if (tip != null) { 
	tip = "<html><center>" + tip.replaceAll("\n", "<br/>") + "</center></html>";
      } 
      addTab(labels[i], null, panels[i], tip);
    }

    LookAndFeelManager lnfManager = LookAndFeelManager.getInstance();
    if (lnfManager.isSubstanceLnF()) { 
      setTabPlacement(SwingConstants.LEFT);
    }

    if (prop != null) {
      prop.setOwner(this);
    }

    addChangeListener(new ChangeListener() {
	public void stateChanged(ChangeEvent e) {
	  Component comp = getSelectedComponent();
	  if (comp instanceof DrawShapePropertyPane) {
	    DrawShapePropertyPane vattr = (DrawShapePropertyPane) comp;
	    vattr.updateAttributes();
	  }
	}
      });

  }

  public void show(int i) {
    if (i >= 0 && i <= 1) {
      setSelectedIndex(i);
    }
  }

  protected JPanel[] panels;

  protected String[] labels;

  protected String[] tabTips;

}
